package socket.handler;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

import message.Message;

public class ClientSocketHandler implements SocketHandler {
	private Socket socket;
	private ObjectInputStream in;
	private ObjectOutputStream out;
	
	public ClientSocketHandler(Socket socket, ObjectInputStream in,
			ObjectOutputStream out) {
		super();
		this.socket = socket;
		this.in = in;
		this.out = out;
	}

	@Override
	public Message readSocket() {
		// TODO Auto-generated method stub
		Message message=null;
		try {
			message=(Message) in.readObject();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return message;
	}

	@Override
	public boolean writeSocket(Message message) {
		// TODO Auto-generated method stub
		try {
			out.writeObject(message);
			out.flush();
			return true;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public void closeSocket() throws IOException {
		// TODO Auto-generated method stub
		in.close();
		out.close();
		socket.close();
	}

	@Override
	public void processMessage(Message message) {
		// TODO Auto-generated method stub
		
	}

}
